//
//  ContentView.swift
//  AAHealKit
//
//  Created by 蔡永康 on 2024/6/27.
//

import SwiftUI
import HuaWeiWearSDK


struct ContentView: View {
    func scan() {
        AAHealKit.shared.bleScanNotifyStart(scanFilters:scanFilters,completion: {result in
            print("goto 开启ble扫描 result = \(result)")
            msglog = ("goto 开启ble扫描 result = \(result)\n") + msglog
            switch result {
            case .success(let code,let msg):
                if 1000 == code {
                    var model:BleAdvertisedInfo = msg.jsonStrToObject(BleAdvertisedInfo.self)!
                    self.mainItem.append(model)
                }
                break
                
            case .failure(let code,let msg):
                print("goto 开启ble扫描 error = \(msg)")
                break
            }
        })
    }
    var body: some View {
        VStack {
            Button( action: {
                print("goto Scan")
                
                self.scan()
                

            } ,label: {
                Text("开始扫描周围设备")
                    .font(.title)
                    .padding(10)
                    .background(Color.blue)
                    .foregroundColor(.white)
            })
            .cornerRadius(15)
            .padding(1)
        }
        .padding()
    }
}

#Preview {
    ContentView()
}
